Impact AIT
Visual Basic 6.0 Edition


 

Return to Index
 ›Data Exchange - TCPIP - VB6
  ›Data Exchange - TCPIP - VB6 - Send Data

Transfer data to and from a Datalogic device

Notes: The default AIT root distribution folder for this application is: /Datalogic/IMPACT/AIT/Data Exchange/TCPIP

Note: If you receive the following error message when you attempt to run any of the included sample files,
     Component 'MSWINSCK.OCX' or one of its dependencies not correctly registered: a file is missing or invalid
you need to install the Visual Basic 6.0 Run-time Files that include the file MSWINSCK.OCX.

Part 1 – Create a connection and send data to the device

Configure the vision device and program
Set the TCP/IP Port with VPM
Create the Visual Basic program

Configure the vision device and program

1.       Start VPM and select the Settings tab.

2.       Select the File Manager, then select the Setup tab.

3.       Copy the file named Light Bulb Inspection.vp from the AIT distribution subfolder /VisualBasic6/Example1/IMPACT Files and paste it into the folder /IMPACT Root/VisionPrograms

4.       Load the file named Light Bulb Inspection.vp.

5.       Open the vision program file named Light Bulb Inspection.vp. (Note: The completed sample program is in the AIT distribution subfolder /VisualBasic6/Example1/IMPACT Files/Light Bulb Inspection TCPIP.vp.)

6.       Add a new task to the program.

7.       Rename “Task” to TCPIP Event Received. See example

8.       Select the “TCP/IP Input” event for the trigger event. See example

9.       Add a Basic tool from the Logic toolbox to the task. This tool will divide the received TCP/IP data string into an IP address and port number. Rename the tool Parse Incoming String.

10.    Enter the following code into the Basic tool. (You can select and copy the text from this page.)

'The split function will divide a string up into sub-strings based on a
'defined string. In this example, tcpip_string is divided into two
'variables, ip_address_string and port_number_int, at the position of the ","

split tcpip_string by "," to ip_address_string, port_number_int

11.    Patch the variable “tcpip_string” from the Basic tool to the task’s inputString port. See example

12.    Save the file and unlock VPM.

Set the TCP/IP Port with VPM

1.       In VPM, select the Settings tab.

2.       Select the General icon.

3.       Under the TCP/IP section, enter 20,000 for the Input Event Port. See example

4.       Click the “Edit” button to select the delimiter.

5.       Click Clear to reset the delimiter.

6.       Select 0x0D CR in the table and click the Append button.

7.       Select 0x0A LF in the table and click Append. The Delimiter Sequence should be OD,0A. See example

8.       Click OK to confirm the selection.

9.       Click the online/offline button in VPM to put the vision device online.

Create the Visual Basic program

1.       Start Microsoft Visual Basic 6.0. (Note: This sample code is in the AIT distribution subfolder /VisualBasic6/Example1/Project.)

2.       Select a new Standard EXE project type.

3.       From the project explorer, select Project1 and press the F4 key.

4.       Rename the project to Impact_TCPIP.

5.       Press CTRL-T to show the component selection dialog box.

6.       Select Microsoft Winsock Control and click OK.

7.       Select the Winsock control from the toolbox and place it on the form.

8.       Select the properties (F4) and change the name to Data_To_Device.

9.       Add a button to the form and change the name and caption to Connect.

10.    Add two labels to the form.

11.    Change the caption of label1 to IP Address and label2 to Port Number.

12.    Add two textboxes to the form.

13.    Change the name of Text1 to IPAddress. Change the text property to your Datalogic device’s IP address (eg. 192.168.105.65) .

14.    Change the name of Text2 to PortNumber and the text property to 20,000.

15.    Double click on the Form and enter the following code. (You may select and copy the code from this page, then paste it into the form.)

   Private Sub Connect_Click()
     'Set the IP address and port number of the Datalogic device
     Data_To_Device.RemoteHost = IPAddress.Text
     Data_To_Device.RemotePort = CInt(PortNumber.Text)
     'The device has to be online before it can receive any TCPIP events
     If Data_To_Device.State = sckClosed Then
      Data_To_Device.Connect
     End If
  End Sub
  Private Sub Data_To_Device_Connect()
       'Send IP Address and port number information to the device
       Data_To_Device.SendData Data_To_Device.LocalIP & "," & Data_To_Device.LocalPort & vbCrLf
  End Sub
  Private Sub Form_Load()
      'Display the IP address and port number of this PC
       Me.Caption = "Local IP Address = " & Data_To_Device.LocalIP & ", Port Number = " & Data_To_Device.LocalPort
  End Sub
  Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
      'Close the port
      Data_To_Device.Close
  End Sub

16.    Save the project.

17.    Make an executable file from the project then run the executable. What does the program User Interface look like?

18.    When you click the Connect button, the Visual Basic program will send the IP Address and Port Number contained in the textbox control's text property to the device. You can view the results in the Basic tool in VPM.

19.    Click the online/offline button in VPM to put the device offline.

20.    Part 2 explains how to add to the Visual Basic program the ability to receive data from the device.

This is the end of part 1. Click here to go to part 2.


©2003-2013 Datalogic Automation Inc. All Rights Reserved